cmake_minimum_required(VERSION 3.8.0)
project(learn_cmake)

# 设置c++标准为c++11
set(CMAKE_CXX_STANDARD 11)
# ???
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -fPIC  -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fPIC  -Werror")
# 设置
set(CMAKE_BUILD_TYPE debug)

# 用cmake安装的其他库, 它们的include和library目录都已经记录下来,可以轻易找到
# 
include(FindPkgConfig)
find_package(Eigen3 REQUIRED)
find_package(glog REQUIRED)
find_package(Ceres REQUIRED)
# 由于某些库可能会同时安装几个版本,  "X.X REQUIRED" 可以在编译时指定版本, 
# 而 "COMPONENTS" 可以指定其中的部分库
find_package(OpenCV 3 REQUIRED COMPONENTS
  opencv_core 
  opencv_imgproc
  opencv_imgcodecs)
find_package(PCL 1.8 REQUIRED  COMPONENTS
  common
  octree
  io
  kdtree
  search
  sample_consensus
  filters
  2d
  geometry
  features
  segmentation)

# 不同cpu架构设置不同的编译
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
  message("this is x86_64")
  add_definitions(-DX86)
elseif()
message("this maybe arm")
  add_definitions(-DARM)
endif()


# 设置子目录, 子目录中有独立的CMakeList.txt用来编译子项目
add_subdirectory(thirdparty/sub1_share)
add_subdirectory(thirdparty/sub2_static)

# 编译成静态库 staticlib.a
add_library(
  staticlib STATIC
  src/staticlib.cpp)
# 包含头文件目录
target_include_directories(staticlib 
 PUBLIC include)
# 包含库目录
# target_link_libraries(staticlib 需要的依赖库)


# 编译成动态库 shared.so
add_library(sharedlib SHARED 
  src/sharedlib.cpp)
# 包含头文件目录
target_include_directories(sharedlib 
 PUBLIC include)
# 包含库目录
# target_link_libraries(sharedlib 需要的依赖库)


# 将部分cpp编译成可执行文件 main
add_executable(main 
src/main.cpp
src/a.cpp)
# 包含头文件目录
target_include_directories(main 
 PUBLIC include
 PUBLIC thirdparty)
# 包含库目录
 target_link_libraries(main
  staticlib 
  sharedlib
  sub1_share
  sub2_static
  glog::glog
  )

